package com.yycx.module.bus.provider.service;

import com.yycx.common.mybatis.base.service.IBaseService;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.module.bus.client.entity.*;
import com.yycx.module.bus.client.enums.SaleTypeEnum;
import com.yycx.module.bus.client.vo.OrderCustomReturn;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单明细 接口
 *
 * @author flyme
 * @date 2020-08-19
 */
public interface BusOrderDetailsService extends IBaseService<BusOrderDetails> {
    /**
     * 更新订单明细相关金额
     *
     * @param busOrder
     */
    void updateByOrder(BusOrder busOrder);

    /**
     * 根据订单ID删除订单明细
     *
     * @param orderId
     * @return
     */
    Boolean delByOrderId(Serializable orderId);

    /**
     * 查询订单明细
     * @param orderId
     * @param saleType
     * @return
     */
    List<BusOrderDetails> selectByOrderId(Long orderId, SaleTypeEnum saleType);


    /**
     * 查询订单明细
     * @param orderId
     * @return
     */
    List<BusOrderDetails> selectByOrderId(Long orderId);

    /**
     * 根据父ID查询
     * @param parentId
     * @param saleType
     * @return
     */
    BusOrderDetails selectByParentId(Long parentId, SaleTypeEnum saleType);

    /**
     * 统计发货金额
     *
     * @param orderId
     * @return
     */
    BigDecimal totalSaleAmount(Long orderId);

    /**
     * 查询发货单明细
     *
     * @param orderId
     * @return
     */
    List<EntityMap> getOrderDetails(Long orderId);




    /**
     * 查询已用资信额度
     *
     * @param deptId
     * @return
     */
    BigDecimal totalReputationAmount(Long deptId);



    /**
     * 拆分订单
     * @param bocr
     * @param fileIds
     * @return
     */
    ResultBody chaiFen(OrderCustomReturn bocr, String fileIds);


    /**
     * 添加退货补货
     * @param orderDetailsId
     * @param saleType
     * @param saleNum
     * @param saleDate
     * @return
     */
    ResultBody addReturnOrderDetails(Long orderDetailsId, Integer saleType, BigDecimal saleNum, String saleDate);

    /**
     * 添加票折商品
     * @param orderDetailsId
     * @param saleAmount
     * @return
     */
    ResultBody addDiscountDetails(Long orderDetailsId, BigDecimal saleAmount);

    /**
     * 删除退补记录
     * @param orderDetailsId
     * @return
     */
    ResultBody deleteTuibu(Long orderDetailsId);


    ResultBody updateLotNo(Long drugsLotId,Long orderDetailsId);

    ResultBody revoke(Long returnId);


    /**
     * 更新认款月份
     * @param renkuanDate
     * @param supplierRetDate2
     * @param orderDetailsId
     * @return
     */
    ResultBody updateRenkuan(String renkuanDate,String supplierRetDate2,Long orderDetailsId);

    /**
     * 更新回款信息
     * @param returnDate
     * @param returnAmount
     * @param orderDetailsId
     * @return
     */
    ResultBody updateHuikuan(String returnDate,BigDecimal returnAmount,Long orderDetailsId);



    /**
     * 根据开票ID查询
     * @param kaipiaoId
     * @return
     */
    List<BusOrderDetails> selectByKaiPiaoId(Long kaipiaoId);

    /**
     * 根据退保证金ID查询
     * @param tbzjId
     * @return
     */
    List<BusOrderDetails> selectByTbzjId(Long tbzjId);



    /**
     * 查询票折明细
     * @param orderId
     * @return
     */
    BusOrderDetails selectPiaozhe(Long orderId);

    /**
     * 查询补货记录
     * @param orderDetailsId
     * @return
     */
    List<BusOrderDetails> selectBuhuo(Long orderDetailsId);


    /**
     * 更新状态
     * @param orderId
     * @param orderDetailsState
     * @return
     */
    Boolean updateOrderDetailsState(Long orderId,BusOrderDetails orderDetails,Integer orderDetailsState);


    /**
     * 更新保证金状态
     * @param orderId
     * @param state
     */
    void updateCustomBondState(Long orderId, Integer state);


    /**
     * 更新退保证金金额
     * @param orderDetailsId
     * @param returnCustomBond
     * @param returnDate
     */
    void updateReturnCustomBond(Long orderDetailsId, BigDecimal returnCustomBond,String returnDate);




    /**
     * 更新垫付款状态
     * @param orderId
     * @param state
     */
    void updateSupplierBondState(BusPayment payment,Long orderId, Integer state);

    /**
     * 更新垫付款状态
     * @param orderId
     * @param state
     */
    void clearSupplierBondState(Long orderId, Integer state);

    /**
     * 更新退垫付信息
     */
    void updateReturnDianfuAmount(BusPayment payment);
    /**
     * 更新退垫付信息
     */
    void updateReturnDianfuId(BusPayment payment,String selectIds);

    /**
     * 删除退垫付信息
     */
     void clearReturnDianfuId(Serializable returnDianfuId);


    /**
     * 统计保证金应收金额
     * @param orderId
     * @return
     */
    BigDecimal totalCustomBond(Long orderId);

    /**
     * 计算发货金额
     * @param orderId
     * @return
     */
    BigDecimal totalSaleNum(Long orderId);

    /**
     * 查询订单明细商品信息
     * @param params
     * @return
     */
    List<EntityMap> selectOrderInfoDetails(Map params);


    /**
     * 更新退保证金信息
     * @param payment
     * @param orderDetailsId
     * @return
     */
    Boolean updateCbReturn(BusPayment payment,Long orderDetailsId);

    /**
     * 更新回款信息
     * @param payment
     * @param orderDetailsId
     * @return
     */
    Boolean updateHuiKuan(BusPayment payment,Long orderDetailsId);


    /**
     * 更新开票信息
     * @param payment
     * @return
     */
    Boolean updateInvoiceInfo(BusPayment payment);

    /**
     * 更新开票信息
     * @param payment
     * @param orderDetailsIds
     * @return
     */
    Boolean updateKaipiaoId(BusPayment payment,String orderDetailsIds);

    /**
     * 更新开票信息
     * @param payment
     * @param orderDetailsIds
     * @return
     */
    Boolean updateKaipiaoId2(BusPayment payment,String orderDetailsIds);

    /**
     * 清空开票信息
     * @param kaipiaoId
     * @return
     */
    Boolean clearInvoiceInfo(Serializable kaipiaoId,Integer settleType);


    /**
     * 更新返款信息
     * @param payment
     * @param kaipiaoId
     * @return
     */
    Boolean updateFankuanInfo(BusPayment payment,Long kaipiaoId);


    /**
     * 更新返款Id
     * @param payment
     * @param kaipiaoId
     * @return
     */
    Boolean updateFankuanId(BusPayment payment,Long kaipiaoId);


    /**
     * 更新结算信息
     * @param payment
     * @param selectIds
     * @return
     */
    Boolean updateJiesuanInfo(BusPayment payment,BigDecimal yesSettleAmount,Integer settleType);


    /**
     * 更新结算信息
     * @param payment
     * @param selectIds
     * @return
     */
    Boolean updateJiesuanId(BusPayment payment,String selectIds,Integer settleType);

    /**
     * 更新结算信息
     * @param jiesuanId
     * @return
     */
    Boolean clearJiesuanInfo(Serializable jiesuanId,Integer settleType);


    /**
     * 清空返款信息
     * @param fankuanId
     * @return
     */
    Boolean clearFankuanInfo(Serializable fankuanId);

    /**
     * 清空返款信息
     * @param returnId
     * @return
     */
    Boolean clearHuiKuanInfo(Serializable returnId);


    /**
     * 更新回款信息
     * @param payment
     * @return
     */
    Boolean updateHuikuanInfo(BusPayment payment);

    /**
     * 清空退市场保证金
     * @param tbzjId
     * @return
     */
     Boolean clearTbzj(Serializable tbzjId);

    /**
     * 更新回款信息
     * @param payment
     * @return
     */
    Boolean updateHuikuanInfo(BusOrderDetails orderDetails,BusOrder order);



    /**
     * 根据认款日期查询回款明细
     * @param deptId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectByReturnDate(Long deptId, String financeMonth, String lastMonth);




    /**
     * 查询部门本期退上期保证金
     * @param deptId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectTuiBenQi(Long deptId, String financeMonth, String lastMonth);

    /**
     * 查询本期调整上期收保证金
     * @param deptId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectBzjBenQi(Long deptId, String financeMonth, String lastMonth);

    /**
     * 查询部门本期结算上期
     * @param deptId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectJiesuanBenQi(Long deptId, String financeMonth, String lastMonth);

    /**
     * 查询部门本期结算上期
     * @param deptId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectJiesuanBenQi2(Long deptId, String financeMonth, String lastMonth);


    /**
     * 查询厂家对账本期回上期回款
     * @param supplierId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectBenQiHuiShagnQi(Long supplierId,String financeMonth, String lastMonth);


    /**
     * 查询未结算明细
     * @param orderDetailsId
     * @return
     */
    List<EntityMap> getNoSettleList(Long orderDetailsId);

    /**
     * 查询厂家对账本期回上期返款
     * @param supplierId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectBenQiFanShagnQi(Long supplierId,String financeMonth, String lastMonth);


    /**
     * 查询厂家对账本期回上期垫付款
     * @param supplierId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectBenQiDianShagnQi(Long supplierId,String financeMonth, String lastMonth);


    /**
     * 查询厂家对账本期退上期垫付款
     * @param supplierId
     * @param financeMonth
     * @param lastMonth
     * @return
     */
    List<EntityMap> selectBenQiTuiDianShagnQi(Long supplierId,String financeMonth, String lastMonth);

    /**
     * 按年月周日统计销售额
     * @param params
     * @return
     */
    ResultBody totalSaleByType(Map params);

    /**
     * 根据批号ID统计
     * @param drugLotId
     * @return
     */
    BigDecimal countByDrugLotId(Long drugLotId);

    /**
     * 根据订单数量
     * @param orderDetailsId
     * @return
     */
    Integer countByOrderDetails(String orderDetailsId);

}
